package com.flower.salary.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.flower.salary.common.utils.LocalUser;
import com.flower.salary.domain.entity.SysLog;
import com.flower.salary.domain.entity.SysUser;
import com.flower.salary.mapper.SysLogMapper;
import com.flower.salary.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-02-27 22:01
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Override
    public int insert(String text, String status) {
        SysLog log = new SysLog();
        log.setIp("127.0.0.1");

        log.setCreateTime(LocalDateTime.now());
        SysUser localUser = LocalUser.getLocalUser();;
        String userName = "管理员";
        if(localUser != null){
            userName = localUser.getUserName();
        }
        log.setUser(userName);
        log.setText(text);
        log.setStatue(status);
        // 插入 数据
        sysLogMapper.insert(log);
        return 0;
    }

    @Override
    public int insert(String text, String username, String status) {
        SysLog log = new SysLog();
        log.setIp("127.0.0.1");
        log.setCreateTime(LocalDateTime.now());
        SysUser localUser = LocalUser.getLocalUser();
        String userName = "管理员";
        if(localUser != null){
            userName = localUser.getUserName();
        }
        log.setUser(userName);
        log.setText(text);
        log.setStatue(status);
        // 插入 数据
        sysLogMapper.insert(log);
        return 0;
    }

    @Override
    public List<SysLog> all() {
        QueryWrapper q = new QueryWrapper();
        List<SysLog> sysLogs = sysLogMapper.selectList(q);
        return sysLogs;
    }
}
